<!--suppress HtmlUnknownTag -->
<root xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href="rds.html"/>

  <?python
      import os
      from base64 import b64encode
      from mnemoply.utils import MonthYear, format_currency, format_date, getBarcodeImage, read_binary_file
      from mnemoply.common_knowledge import month_captions
  ?>

  <report>
    <pages>
      <?python
          objs = [model.TemporaryPaymentRecord.get(int(x)) for x in ids]
      ?>

      <page py:if="tpr.payment == 0" py:for="tpr in objs">
        <tpr py:content="tpr.id"></tpr>
        <trend py:if="tpr.trend" py:content="tpr.trend.title"></trend>
        <if py:if="tpr.student" py:strip="True">
          <student py:content="tpr.student.fullName"></student>
          <student_short>${tpr.student.surname} ${tpr.student.forename}</student_short>
          <debt>${tpr.student.balance}</debt>
        </if>
        <if py:if="not tpr.student" py:strip="True">
          <student> </student>
          <student_short> </student_short>
          <debt> </debt>
        </if>
        <temp_name>${tpr.tempSurname} ${tpr.tempForename} ${tpr.tempPatronymic}</temp_name>
        <temp_name_short>${tpr.tempSurname} ${tpr.tempForename}</temp_name_short>
        <phone>${tpr.phone}</phone>
        <organization py:if="tpr.organization">${tpr.organization.title}</organization>
        <organization py:if="not tpr.organization"> </organization>
        <prepayment_amount py:if="tpr.tariff" py:content="tpr.tariff.prepaymentCost"></prepayment_amount>
        <prepayment_amount py:if="not tpr.tariff">0.00</prepayment_amount>
        <today py:content="format_date()"></today>
        <?python
            env = model.environment.Environment
            prefix = env.getValue('payment_type_temporary')
            barcodes_dir = "barcodes"
            barcode_num = prefix + str(tpr.id).rjust(6, "0")
            barcode_file = getBarcodeImage(barcode_num, barcodes_dir)

            barcode_b64 = b64encode(read_binary_file("./" + barcode_file))
        ?>
        <barcode_num py:content="'barcode_'+str(barcode_num)"></barcode_num>
        <barcode>
          <filename>${barcode_num}.png</filename>
          <data py:content="barcode_b64"></data>
        </barcode>
      </page>
    </pages>
  </report>

</root>
